package cn.itrip.service.impl;

import cn.itrip.entity.ItripOrderLinkUser;
import cn.itrip.dao.ItripOrderLinkUserDao;
import cn.itrip.service.ItripOrderLinkUserService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (ItripOrderLinkUser)表服务实现类
 *
 * @author makejava
 * @since 2022-04-14 22:34:59
 */
@Service("itripOrderLinkUserService")
public class ItripOrderLinkUserServiceImpl implements ItripOrderLinkUserService {
	@Resource
	private ItripOrderLinkUserDao itripOrderLinkUserDao;

	/**
	 * 通过ID查询单条数据
	 *
	 * @param id 主键
	 * @return 实例对象
	 */
	@Override
	public ItripOrderLinkUser queryById(Long id) {
		return this.itripOrderLinkUserDao.queryById(id);
	}

	/**
	 * 分页查询
	 *
	 * @param itripOrderLinkUser 筛选条件
	 * @param pageRequest        分页对象
	 * @return 查询结果
	 */
	@Override
	public Page<ItripOrderLinkUser> queryByPage(ItripOrderLinkUser itripOrderLinkUser, PageRequest pageRequest) {
		long total = this.itripOrderLinkUserDao.count(itripOrderLinkUser);
		return new PageImpl<>(this.itripOrderLinkUserDao.queryAllByLimit(itripOrderLinkUser, pageRequest), pageRequest, total);
	}

	/**
	 * 新增数据
	 *
	 * @param itripOrderLinkUser 实例对象
	 * @return 实例对象
	 */
	@Override
	public ItripOrderLinkUser insert(ItripOrderLinkUser itripOrderLinkUser) {
		this.itripOrderLinkUserDao.insert(itripOrderLinkUser);
		return itripOrderLinkUser;
	}

	/**
	 * 修改数据
	 *
	 * @param itripOrderLinkUser 实例对象
	 * @return 实例对象
	 */
	@Override
	public ItripOrderLinkUser update(ItripOrderLinkUser itripOrderLinkUser) {
		this.itripOrderLinkUserDao.update(itripOrderLinkUser);
		return this.queryById(itripOrderLinkUser.getId());
	}

	/**
	 * 通过主键删除数据
	 *
	 * @param id 主键
	 * @return 是否成功
	 */
	@Override
	public boolean deleteById(Long id) {
		return this.itripOrderLinkUserDao.deleteById(id) > 0;
	}
}
